<html>
<head><meta charset="utf-8"><title>Fortified symbols and Rust · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html">Fortified symbols and Rust</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222000435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222000435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Baublitz <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222000435">(Jan 07 2021 at 21:03)</a>:</h4>
<p>hi all, I recently bumped into an issue where the automated security checks at my company (which primarily target C) are complaining that our executable lost some fortified symbols. from the research I've done, it seems like fortified symbols are primarily a C concept so I'm curious how Rust handles this. does the compiler have guidelines around when it generates fortified symbols? is this done more on a case by case basis?</p>



<a name="222000674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222000674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222000674">(Jan 07 2021 at 21:05)</a>:</h4>
<p>the closest thing I found was <a href="https://wiki.debian.org/Hardening#DEB_BUILD_HARDENING_FORTIFY_.28gcc.2Fg.2B-.2B-_-D_FORTIFY_SOURCE.3D2.29">https://wiki.debian.org/Hardening#DEB_BUILD_HARDENING_FORTIFY_.28gcc.2Fg.2B-.2B-_-D_FORTIFY_SOURCE.3D2.29</a>, which looks entirely unrelated to rust</p>



<a name="222000806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222000806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222000806">(Jan 07 2021 at 21:06)</a>:</h4>
<p>buffer overruns can't happen in safe rust (without some serious unsoundness bugs in the compiler or standard library)</p>



<a name="222001074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222001074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Baublitz <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222001074">(Jan 07 2021 at 21:08)</a>:</h4>
<p>my understanding is that this is related to symbols used by the standard library (it appears to be something related to readlink, etc.)</p>



<a name="222001687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222001687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222001687">(Jan 07 2021 at 21:13)</a>:</h4>
<p>hey <span class="user-mention" data-user-id="228098">@John Baublitz</span> -- I'm <code>jistone</code> from our IRC, if you didn't know</p>



<a name="222001794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222001794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222001794">(Jan 07 2021 at 21:14)</a>:</h4>
<p>it is entirely expected that Rust std isn't using those fortified symbols</p>



<a name="222001927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222001927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222001927">(Jan 07 2021 at 21:15)</a>:</h4>
<p>they depend on <code>__builtin_object_size</code> tracking implemented in GCC and Clang (not LLVM)</p>



<a name="222002189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222002189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Baublitz <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222002189">(Jan 07 2021 at 21:17)</a>:</h4>
<p>gotcha! from our conversation, it sounded like this was evaluated on a case by case basis so I just wanted to get some more info beyond "this seems like a C thing"</p>



<a name="222004316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222004316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222004316">(Jan 07 2021 at 21:34)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> in case you're curious about <code>_FORTIFY_SOURCE</code>, Red Hat has some detailed articles too:<br>
<a href="https://access.redhat.com/blogs/766093/posts/1976213">https://access.redhat.com/blogs/766093/posts/1976213</a><br>
<a href="https://access.redhat.com/blogs/766093/posts/3606481">https://access.redhat.com/blogs/766093/posts/3606481</a></p>



<a name="222004635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222004635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222004635">(Jan 07 2021 at 21:37)</a>:</h4>
<p>and more recent work on Clang: <a href="https://developers.redhat.com/blog/2020/02/11/toward-_fortify_source-parity-between-clang-and-gcc/">https://developers.redhat.com/blog/2020/02/11/toward-_fortify_source-parity-between-clang-and-gcc/</a></p>



<a name="222005975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222005975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222005975">(Jan 07 2021 at 21:48)</a>:</h4>
<div class="codehilite" data-code-language="C"><pre><span></span><code><span class="n">__fortify_function</span> <span class="n">__wur</span> <span class="kt">char</span> <span class="o">*</span>
<span class="n">fgets</span> <span class="p">(</span><span class="kt">char</span> <span class="o">*</span><span class="n">__restrict</span> <span class="n">__s</span><span class="p">,</span> <span class="kt">int</span> <span class="n">__n</span><span class="p">,</span> <span class="kt">FILE</span> <span class="o">*</span><span class="n">__restrict</span> <span class="n">__stream</span><span class="p">)</span>
<span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="n">__bos</span> <span class="p">(</span><span class="n">__s</span><span class="p">)</span> <span class="o">!=</span> <span class="p">(</span><span class="kt">size_t</span><span class="p">)</span> <span class="mi">-1</span><span class="p">)</span>
    <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">__builtin_constant_p</span> <span class="p">(</span><span class="n">__n</span><span class="p">)</span> <span class="o">||</span> <span class="n">__n</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">)</span>
  <span class="k">return</span> <span class="n">__fgets_chk</span> <span class="p">(</span><span class="n">__s</span><span class="p">,</span> <span class="n">__bos</span> <span class="p">(</span><span class="n">__s</span><span class="p">),</span> <span class="n">__n</span><span class="p">,</span> <span class="n">__stream</span><span class="p">);</span>

      <span class="k">if</span> <span class="p">((</span><span class="kt">size_t</span><span class="p">)</span> <span class="n">__n</span> <span class="o">&gt;</span> <span class="n">__bos</span> <span class="p">(</span><span class="n">__s</span><span class="p">))</span>
  <span class="k">return</span> <span class="n">__fgets_chk_warn</span> <span class="p">(</span><span class="n">__s</span><span class="p">,</span> <span class="n">__bos</span> <span class="p">(</span><span class="n">__s</span><span class="p">),</span> <span class="n">__n</span><span class="p">,</span> <span class="n">__stream</span><span class="p">);</span>
    <span class="p">}</span>
  <span class="k">return</span> <span class="n">__fgets_alias</span> <span class="p">(</span><span class="n">__s</span><span class="p">,</span> <span class="n">__n</span><span class="p">,</span> <span class="n">__stream</span><span class="p">);</span>
<span class="p">}</span> <span class="c1">//*</span>
</code></pre></div>
<p>I forgot what reading glibc is like :(</p>



<a name="222006003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222006003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222006003">(Jan 07 2021 at 21:48)</a>:</h4>
<p>oh yay, hard tabs they assume are 8 spaces too</p>



<a name="222008325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Fortified%20symbols%20and%20Rust/near/222008325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Fortified.20symbols.20and.20Rust.html#222008325">(Jan 07 2021 at 22:06)</a>:</h4>
<p>seems preferable to memory freeze/thaw schemes</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>